﻿<%@ Page Language="C#" Title="轴载监测" MasterPageFile="~/W_View/PageMaster.Master" CodeBehind="S_AxleloadPage.aspx.cs" Inherits="STHPMS1.Web.W_View.Survey.S_AxleloadPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <%= UiHelper.RefJsFileHtml("/Scripts/Control/datagrid.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/Control/dropdown.js")%>
     <%= UiHelper.RefJsFileHtml("/Scripts/Jquery/ajaxfileupload.js")%>
    <script type="text/javascript">
        var actionFlag = 0; //新增或导入的应用桩号标记
        var action;
        function Stake_Apply(o)
        {
            action = o;
            $('#dlg1').dialog('open');
        }

        function Stake_Enable()
        {
            var rdwayid = $('#Rdwayid').combobox('getValue');
            var beginmp = $('#add_Beginmp').numberbox('getValue');
            var endmp = $('#add_Endnmp').numberbox('getValue');
            var direct = $('#direction_Dictid').combobox('getValue');

            var text = actionFlag == 0 ? $('#ApplyStake').textbox('getText') : $('#ApplyStake2').textbox('getText');
            var value = rdwayid + "," + beginmp + "," + endmp + "," + direct + ";";
            if (!text) text = "";
            if (action == 0)
            {
                if (text.indexOf(value) >= 0) text = text.replace(value, "");
            } else
            {
                if (text.indexOf(value) < 0) text += value;
            }

            if (actionFlag == 0)
                $('#ApplyStake').textbox('setValue', text);
            else
                $('#ApplyStake2').textbox('setValue', text);
            
            $('#dlg1').dialog('close');
        }

        function S_AxleloadEdit(flag) {
            var row = $('#dg').datagrid('getSelected');
            var title = "";
            if (flag == 0) {
                if (!row) {
                    $.messager.alert('消息提示', '编辑数据时，请选择一项!', 'warning');
                    return;
                }
                $('#fm').form('load', row);
                title = "新增测试数据";

                $('#row3').hide();
                $('#row4').hide();
                $('#row5').hide();
                if (row.Eaweight3)
                {
                    $('#row3').show();
                }
                if (row.Eaweight4) {
                    $('#row5').show();
                }
                $('#Obvtm').datebox('readonly', true);
                $('#Statname').textbox('readonly', true);
            }
            else {
                $('#fm').form('clear');
                title = "编辑测试数据";
                $('#row4').show();
                $('#Obvtm').datebox('readonly', false);
                $('#Statname').textbox('readonly', false);
            }

            $('#dlg').dialog('open');
        }              

        function S_AxleloadDel() {
            var row = $('#dg').datagrid('getSelected');
            if (!row) {
                $.messager.alert('消息提示', '删除数据时，请选择一项!', 'warning');
                return;
            }

            deleteData($('#dg'), $('#dlg'), "/api/axleload");
        }



        function search(n,o) {
            var address = $('#Statname1').textbox("getValue");
            var checkDate = $('#checkDate1').datebox('getValue');  //注意.datebox('getValue')

            var url = '/api/axleload';
            var urlParam = "";
            if (address != "" && address != "0") urlParam += "address=" + encodeURI(address) + "&";
            if (checkDate != "") urlParam += "checkDate=" + encodeURI(checkDate) + "&";
            if (urlParam != "") {
                urlParam = "?" + urlParam.substring(0, urlParam.length - 1);
                url = url + urlParam;
            }

            $('#dg').datagrid({ url: url, pageNumber: 1 });
        }
       

        $(function () {
            var number= '<%= Page.RouteData.Values["page"] %>';
            var size = '<%= Page.RouteData.Values["size"] %>';

            dataGridBind($('#dg'), '/api/axleload', '轴载监测列表显示', $('#tb'), number, size);

            $('.validatebox-text').bind('blur', function () {
                $(this).validatebox('enableValidation').validatebox('validate');
            });
        })

        
    </script>    


    <script>
        //导入的点击事件
        function impt() {
            actionFlag = 1; //导入时的应用桩号
            $("#linkUpload").text("上传");
            $('#ApplyStake2').textbox('setValue', '');//清空原来的应用桩号
            $('#dlgImport').dialog('open');

        }

        function closeFile() {
            $("#linkUpload").text("上传");
            $('#dlgImport').dialog('close');
            $("#fileHid").val('');//清空隐藏域
        }


        //上传
        function ajaxFileUpload() {
            $.ajaxFileUpload
            (
                {
                    url: '/api/axleload/uploadFile', //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'file1', //文件上传域的ID
                    dataType: 'string', //返回值类型 一般设置为json
                    success: function (data)  //服务器成功响应处理函数
                    {
                        var file = data;
                        //写入隐藏域
                        $("#fileHid").val(file);
                        $("#linkUpload").text("上传成功");
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);

                    }
                }
            )
            return false;
        }
        //上传文件验证
        function upLoad() {
            if ($("#linkUpload").text() == "上传") {
                var file = $("#file1").val();//上传文件
                if (file == "") {
                    alert("请选择上传数据");
                    return;
                }
                else {
                    var extStart = file.lastIndexOf(".");
                    var ext = file.substring(extStart, file.length).toUpperCase();
                    if (ext != ".XLS" && ext != ".XLSX") {
                        alert("请上传有效Excel文件");
                        return;
                    }
                }
                ajaxFileUpload();
            }
        }
        //导入处理
        function saveFile() {
           
            var file = $("#fileHid").val();//上传后的Excel路径
            if (file == "") {
                alert("请上传数据文件");
                return;
            }
            $.messager.progress({
                title: '请等待',
                msg: '正在处理中...'
            });
            $.ajax({
                url: "/api/axleload/saveFile?file=" + encodeURI(file) ,
                type: "post",
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (msg) {
                    $("#fileHid").val('');//清空隐藏域
                    $('#dlgImport').dialog('close');
                    search(null, null);
                },

                error: function (msg) {
                    //错误处理 

                    $.messager.alert('错误提示', msg.responseText, "error");
                    closeFile();
                }
            });
        }

    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table id="dg" class="easyui-datagrid content-place"  ajaxCached="false"  >
        <thead>
            <tr>
                <th data-options="field:'Axleid',editor:'text',width:300,align:'center',hidden:true">轴载ID</th>
                <th data-options="field:'Obvtm',editor:'datebox',width:160,align:'center' " formatter="formatDate" >观测日期</th>
                <th data-options="field:'Statname',editor:'text',width:160,align:'center' ">观测地点</th>
                <th data-options="field:'His_Version',editor:'numberbox',width:80,align:'center' ,hidden:true">养护版本</th>
                <th data-options="field:'Repreveh_Dictid',editor:'numberbox',width:160,align:'center' " formatter="formatCar">代表车型</th>
                <th data-options="field:'Ealf_Dictid',editor:'numberbox',width:160,align:'center' " formatter="formatShaft">轴型</th>
                <th data-options="field:'Eaweight1',editor:'numberbox',width:80,align:'center' ">轴重1</th>
                <th data-options="field:'Eaweight2',editor:'numberbox',width:80,align:'center' ">轴重2</th>
                <th data-options="field:'Eaweight3',editor:'numberbox',width:80,align:'center' ">轴重3</th>
                <th data-options="field:'Eaweight4',editor:'numberbox',width:80,align:'center' ">轴重4</th>
                <th data-options="field:'Applyid',editor:'text',width:300,align:'center',hidden:true">应用区间ID</th>
            </tr>
        </thead>
    </table>
   
    <!--测试数据命令-->
    <div id="tb">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="S_AxleloadEdit(-1)">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="S_AxleloadEdit(0)">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="S_AxleloadDel()">删除</a>
        <a href="/down?type=zz" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">模板下载</a>
         <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true" onclick="impt()">导入</a>
	    <input id="checkDate1" class="easyui-datebox"  data-options="prompt:'观测日期',onChange:search"/>
        <input id="Statname1"  class='easyui-validatebox easyui-textbox' data-options="prompt:'观测地点',onChange:search"" />
    </div>

    <!--测试详细页面-->
    <div id="dlg" class="easyui-dialog" title="保存数据" style="width:360px;height:300px;padding:10px" closed="true"  data-options="
				iconCls: 'icon-save',   
				buttons: '#dlg-buttons',
                modal:true
			">
        <form id="fm" method="post" action="/api/axleload">
            <table>		
                <tr style="display:none">
                    <td>轴载ID:</td>
                    <td><input  name='Axleid' class='easyui-validatebox easyui-textbox'  /></td>
                </tr>	     
                <tr style="display:none">
                    <td>应用区间ID:</td>
                    <td><input  name='Applyid' class='easyui-validatebox easyui-textbox'  /></td>
                </tr>
                <tr>
                    <td>观测日期:</td>
                    <td><input id="Obvtm" name='Obvtm' class='easyui-validatebox easyui-datebox'  data-options="required:true" /></td>
                </tr>
                <tr>
                    <td>观测地点:</td>
                    <td><input id="Statname" name='Statname' class='easyui-validatebox easyui-textbox'  /></td>
                </tr>            
                 <tr style="display:none">
                    <td>养护版本:</td>
                    <td><input name='His_Version' class='easyui-numberbox' data-options="required:true,readonly:true"/></td>
                </tr> 
                <tr>
                    <td>代表车型:</td>
                    <td><input name='Repreveh_Dictid'  class="easyui-validatebox  easyui-combobox" data-options="prompt:'代表车型',panelHeight:'auto',valueField:'id',textField:'text',url:'/api/data/car',method:'get' ,onSelect:function(rect){ 
                            var data = [];
                            
                            switch(rect.id)
                            {
                                case 1000:{
                                        data.push({ 'text': '1s+1s', 'id': '1s+1s' });
                                        break;
                                    }
                                case 1001:{
                                        data.push({ 'text': '1s+1s', 'id': '1s+1s' });
                                        break;
                                    }
                                case 1002:{
                                        data.push({ 'text': '1s+1d', 'id': '1s+1d' });
                                        break;
                                    }
                                case 1003:{
                                        data.push({ 'text': '1s+3d', 'id': '1s+3d' },{ 'text': '2s+1d', 'id': '2s+1d' });
                                        break;
                                    }
                                case 1004:{
                                        data.push({ 'text': '1s+1s', 'id': '1s+1s' });
                                        break;
                                    }
                                case 1005:{
                                        data.push({ 'text': '1s+1d', 'id': '1s+1d' });
                                        break;
                                    }
                                case 1006:{
                                        data.push({ 'text': '1s+1s+2d', 'id': '1s+1s+2d' },{ 'text': '1s+1s+3d', 'id':  '1s+1s+3d' },{ 'text': '1s+2s+3d', 'id': '1s+2s+3d' },{ 'text': '2s+1s+3d', 'id': '2s+1s+3d' },{ 'text': '1s+2d+1d+1d', 'id': '1s+2d+1d+1d' });
                                        break;
                                    }
                                case 1007:{
                                        data.push({ 'text': '1s+1s+3d', 'id':  '1s+1s+3d' },{ 'text': '1s+2s+3d', 'id': '1s+2s+3d' },{ 'text': '2s+1s+3d', 'id': '2s+1s+3d' },{ 'text': '1s+2d+1d+1d', 'id': '1s+2d+1d+1d' });
                                        break;
                                    }
                                case 1008:{
                                        data.push({ 'text': '1s+1s', 'id': '1s+1s' });
                                        break;
                                    }
                            }         
                           $('#Ealf_Dictid').combobox('loadData', data).combobox('clear');
                        }"/></td>
                </tr>
                <tr>
                    <td>轴型:</td>
                    <td><input id="Ealf_Dictid" name='Ealf_Dictid'  class="easyui-validatebox  easyui-combobox" data-options="prompt:'轴型',panelHeight:'auto',valueField:'id',textField:'text',onSelect:function(rect){ 
                            if(rect.id)
                            {
                                var val=rect.id.split('+');
                               
                                $('#row3').hide();
                                $('#row5').hide();

                                if(val.length==3)
                                {
                                    $('#row3').show();
                                }
                                else if(val.length==4)
                                {
                                    $('#row3').show();
                                    $('#row5').show();
                                }
                            }    
                       
                        }"/></td>
                </tr>
                <tr>
                    <td>轴重1:</td>
                    <td><input name='Eaweight1' class='easyui-validatebox easyui-numberbox'  data-options='min:0,precision:2' /></td>
                </tr>
                <tr>
                    <td>轴重2:</td>
                    <td><input name='Eaweight2' class='easyui-validatebox easyui-numberbox'  data-options='min:0,precision:2' /></td>
                </tr>
                <tr id="row3">
                    <td>轴重3:</td>
                    <td><input name='Eaweight3' class='easyui-validatebox easyui-numberbox'  data-options='min:0,precision:2' /></td>
                </tr>
                 <tr id="row5">
                    <td>轴重4:</td>
                    <td><input name='Eaweight4' class='easyui-validatebox easyui-numberbox'  data-options='min:0,precision:2' /></td>
                </tr>
                 <tr id="row4">
                    <td>应用桩号:</td>
                    <td><input id="ApplyStake" name='ApplyStake' class='easyui-validatebox easyui-textbox'  data-options='readonly:true,min:0,precision:2' />
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="Stake_Apply(-1)" title="添加应用桩号"></a>
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="Stake_Apply(0)" title="删除应用桩号"></a>
                    </td>
                </tr>
		    </table>
        </form>
        
        <div id="dlg1" class="easyui-dialog" title="应用区间" style="width:200px;height:170px;padding:10px" closed="true" data-options="modal:true">
            <input id="Rdwayid" name='Rdwayid'  class="easyui-validatebox  easyui-combobox" data-options="prompt:'路线编号',panelHeight:'auto',valueField:'Rdwayid',textField:'Rdwayid',url:'/api/roadway/all',method:'get' ,onSelect:function(rect){ 
                            var data = [];
                            if(rect.Dire_Ornot)
                            {
                                data.push({ 'text': '全幅', 'id': 13 });
                            }
                            else
                            {
                                data.push({ 'text': '上行', 'id': 11 });
                                data.push({ 'text': '下行', 'id': 12 });
                            }
                           $('#direction_Dictid').combobox('loadData', data).combobox('clear');
                        }"/>
            <input id="add_Beginmp" name='add_Beginmp' class='easyui-validatebox easyui-numberbox' data-options="prompt:'起始桩号',min:0,precision:2" />  
            <input id="add_Endnmp" name='add_Endnmp' class='easyui-validatebox easyui-numberbox' data-options="prompt:'结束桩号',min:0,precision:2" />  
            <input id="direction_Dictid" name='direction_Dictid'  class="easyui-combobox"  data-options="prompt:'行车方向',panelHeight:'auto',valueField:'id',textField:'text' "/>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="Stake_Enable()">确定</a>
        </div>
    </div>

    <!--编辑数据命令-->
    <div id="dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:sumbitData($('#dg'),$('#dlg'))">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')">取消</a>
	</div>
       <!--导入数据-->
    <div id="dlgImport" class="easyui-dialog" title="导入数据" style="width: 400px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttonsImport'
			">
      
            <table>
                
               
                <tr>
                    <td>导入源:</td>
                    <td>
                      
                        <input id="fileHid" type="hidden" />
                        <input type="file" id="file1" name="file1" style="width: 160px"/>
                        <a href="javascript:void(0)" id="linkUpload"  onclick="javascript:upLoad();">上传</a>
                    </td>
                </tr>
            </table>
      
    </div>
    <!--导入数据命令-->
    <div id="dlg-buttonsImport">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:saveFile();">确定</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:closeFile()">取消</a>
    </div>
</asp:Content>
